<template>
  <div>
    <div
      class="product-window address_window group-con"
      :class="info.flag === true ? 'on' : ''"
    >
      <div class="title">
        确认收货地址
      </div>
      <div class="address_box">
        <div
          class="add_new"
          v-if="!Object.keys(info.address).length"
          @click="addAddress(1)"
        >
          <span>添加新的收货地址</span>
          <span>
            <img class="icon" src="../assets/images/cutPrice/right.png" alt="">
          </span>
        </div>
        <div class="info" v-else @click="addAddress(2)">
          <div class="icon">
            <img src="../assets/images/address-icon.png" alt="" />
          </div>
          <div class="right">
            <div class="tel_name">
              <span class="name">{{ info.address.real_name }}</span>
              <span class="tel">{{ info.address.phone }}</span>
              <img class="edit" src="../assets/images/cutPrice/edit.png" alt="">
            </div>
            <div class="detail">
              {{ info.address.province }} {{ info.address.city }}
              {{ info.address.district }} {{ info.address.detail }}
            </div>
          </div>
        </div>
      </div>
      <div class="store_info">
        <div class="left">
          <img :src="info.storeInfo.image" alt="" />
        </div>
        <div class="right">
          <div class="store_name">
            {{ info.storeInfo.store_name }}
          </div>
          <div class="attr">
            <div class="num">规格：{{ info.storeInfo.attrValue }}</div>
            <div class="num">数量：{{ info.storeInfo.cart_num }}</div>
          </div>
        </div>
      </div>
      <div class="button" v-show="buyType == 2" @click="toCut(false)">开始邀请好友砍价</div>
      <div class="button" v-show="buyType == 1" @click="toBuy(true)">立即购买</div>
    </div>
    <div
      class="mask"
      @touchmove.prevent
      :hidden="info.flag === false"
      @click="closeAttr"
    />
  </div>
</template>

<script>
import dialog from "@utils/dialog";
export default {
  props: {
    info: {
      default: Object,
      value: () => {}
    },
    buyType: {
      default: [Number, String],
      value: 1
    }
  },
  mounted() {
  },
  methods: {
    addAddress(type) {
      const path = type == 1 ? "/user/add_address" : "/user/add_manage";
      this.$router.push(path);
    },
    closeAttr() {
      this.$emit("changeFun", { action: "editAddress", value: false });
    },
    // 立即购买
    toBuy(){
      if(!this.info.address.id){
        return this.$dialog.toast({mes:'请填写收货地址'})
      }
      this.$emit("changeFun", { action: "editAddress", value: false });
      this.$emit("changeFun", { action: "isBuyNow", value: true });
    },
    // 砍价
    toCut(){
      if(!this.info.address.id){
        return this.$dialog.toast({mes:'请填写收货地址'})
      }
      const fun = dialog.confirm(() =>{
        this.$emit("changeFun", { action: "editAddress", value: false });
        this.$emit("changeFun", { action: "isBuyNow", value: false });
      },`本次活动一共可以创建${this.info.total_num}个砍价订单，当前是第${this.info.cur_num}个，是否创建该砍价订单`)
      fun()
    }
  }
};
</script>

<style lang="scss" rel="stylesheet/scss" scoped>
.address_window {
  width: 100%;
  height: 8.46rem;
  .title {
    height: 1rem;
    padding: 0.3rem 0;
    box-sizing: border-box;
    font-size: 0.3rem;
    font-weight: 500;
    color: #000000;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    text-align: center;
  }
  .address_box {
    padding: 0.4rem 0;
    margin: 0 0.4rem;
    box-sizing: border-box;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    .add_new {
      width: 100%;
      height: 1.12rem;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 0.3rem 0 0.2rem;
      box-sizing: border-box;
      background: rgba(245, 166, 35, 0.05);
      font-size: 0.28rem;
      font-family: Helvetica;
      color: #eb9200;
      line-height: 0.34rem;
      letter-spacing: 1px;
      margin: 0.18rem 0 0.38rem 0;
      .icon{
        width:0.2rem;
        height: 0.28rem;
      }
    }
    .info {
      display: flex;
      align-items: center;
      .icon {
        width: 0.44rem;
        height: 0.44rem;
        margin-right: 0.2rem;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .right {
        flex: 1;
        .tel_name {
          font-size: 0.3rem;
          font-weight: bold;
          color: #000000;
          position: relative;
          .tel {
            opacity: 0.5;
            margin-left: 0.2rem;
            font-weight: 500;
          }
          .edit{
            position: absolute;
            right:0;
            top:0;
            width:0.32rem;
            height:0.32rem;
          }
        }
        .detail {
          font-size: 0.3rem;
          font-weight: 400;
          color: #000000;
          margin-top: 0.2rem;
        }
      }
    }
  }
  .store_info {
    display: flex;
    padding: 0.4rem 0.4rem 0;
    box-sizing: border-box;
    .left {
      width: 1.8rem;
      height: 1.8rem;
      margin-right: 0.2rem;
      
      img {
        width: 100%;
        height: 100%;
        border-radius: 0.16rem;
      }
    }
    .right {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      flex: 1;
      .store_name {
        font-size: 0.26rem;
        font-weight: 500;
        color: #000000;
      }
      .attr {
        font-size: 0.24rem;
        font-weight: 400;
        color: #000000;
        opacity: 0.6;
        line-height: 0.24rem;
        .num:first-child {
          margin-bottom: 0.16rem;
        }
      }
    }
  }
  .button {
    position: absolute;
    bottom: 0.8rem;
    width: 6.7rem;
    height: 0.84rem;
    background: linear-gradient(270deg, #fa2b37 0%, #ff525d 100%);
    border-radius: 0.08rem;
    font-size: 0.3rem;
    font-weight: bold;
    color: #ffffff;
    margin-left: 0.4rem;
    text-align: center;
    line-height: 0.84rem;
  }
}
</style>
